package com.hqhy.like.stock.service.impl;

import com.hqhy.like.common.pojo.vo.PageData;
import com.hqhy.like.stock.dao.persist.repository.ITotalRepository;
import com.hqhy.like.stock.pojo.dto.TotalUpdateDTO;
import com.hqhy.like.stock.pojo.entity.Total;
import com.hqhy.like.stock.pojo.vo.TotalListItemVO;
import com.hqhy.like.stock.service.ITotalService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class TotalServiceImpl implements ITotalService {

    @Value("${like.dao.default-query-page-size}")
    private Integer defaultQueryPageSize;
    @Autowired
    private ITotalRepository totalRepository;


    @Override
    public int update(Long id, String notes) {
        log.debug("开始处理【总库存修改备注】的业务，id：{}，备注：{}", id, notes);

        Total total = new Total();
        total.setId(id);
        total.setNotes(notes);
        return totalRepository.updateById(total);
    }

    @Override
    public TotalUpdateDTO selectTotalById(Long id) {
        return totalRepository.selectTotalById(id);
    }

    @Override
    public PageData<TotalListItemVO> list(Integer pageNum, Integer size) {
        log.debug("开始处理【查询总库存列表】的业务，页码：{}，每页显示数量：{}", pageNum, size);
        Integer pageSize = size == null ? defaultQueryPageSize : size;
        return totalRepository.list(pageNum, pageSize);
    }


}
